package com.szh.te.config;

import cn.hutool.core.util.StrUtil;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * sentinel 作做授权用的配置类
 */
@Component
public class HeaderOriginParserSentinel implements RequestOriginParser {
    private static final String SENTINEL_ORIGIN_NAME = "origin";

    @Override
    public String parseOrigin(HttpServletRequest request) {
        // 1-获取请求头
        String origin = request.getHeader(SENTINEL_ORIGIN_NAME);
        if (StrUtil.isBlank(origin)) {
            origin = "blank";
        }
        return origin;
    }
}
